#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    long long pickGifts(vector<int>& gifts, int k) {
        priority_queue<int> q;
        for (int i = 0; i < gifts.size(); i++)
            q.push(gifts[i]);
        long long sum = 0;
        for (int i =0; i < k; i++) {
            int s = q.top();
            s = (int)sqrt(s);
            q.pop();
            q.push(s);
        }
        while (!q.empty()) {
            int k = q.top();
            sum += k;
            q.pop();
        }
        return sum;
    }
};